2 Finds the intersection between two lines (Not segments!
4 Line 1 passes through points (x0, y0) and (x1, y1).
5 Line 2 passes through points (x2, y2) and (x3, y3).
7 Handles the case when the 2 lines are the same (infinite
9 parallel (no intersection) or only one intersection.
11 void line_line_intersection(double x0
, double y0
,
15 double x3
, double y3
){
20 double t0
= (y3
-y2
)*(x0
-x2
)-(x3
-x2
)*(y0
-y2
);
21 double t1
= (x1
-x0
)*(y2
-y0
)-(y1
-y0
)*(x2
-x0
);
22 double det
= (y1
-y0
)*(x3
-x2
)-(y3
-y2
)*(x1
-x0
);
25 if (fabs(t0
) < EPS
|| fabs(t1
) < EPS
){
35 double x
= x0
+ t0
*(x1
-x0
);
36 double y
= y0
+ t0
*(y1
-y0
);
37 //intersection is point (x, y)
38 printf("POINT %.2lf %.2lf\n", x
, y
);